<?php

class Room_avail extends CI_Model {

    function __construct() {
        parent::__construct();
    }

   function listRateType() {
        $sql = "SELECT room_number, room_type_name
				FROM room a
				JOIN room_type b ON a.room_type_id = b.room_type_id";
        $result = $this->db->query($sql);

        return $result->result_array();
    }

    function listRateAjax($room_number) {
        $sql = "SELECT concat_ws( ' ', b.resv_status,d.guest_name  ) as gabungan , b.resv_id, d.guest_name,c.resv_room_date
			 FROM room a, reservation b, reservation_room c, guest d
				WHERE a.room_number = b.room_number
			AND b.resv_id = c.resv_id
			AND b.guest_id = d.guest_id
			AND b.room_number =".$room_number;
        		$result = $this->db->query($sql);

        		return $result->result_array();

    
	}
	
	function select_room_type() {
		$this->db->select('*');
		$this->db->from('room_type');
		$this->db->order_by('room_type_name', 'asc');
		$this->db->where('deleted', 'no');
		
		return $this->db->get();
	}
	
	function select_room_by_type($room_type_id) {
		$this->db->select('*');
		$this->db->from('room');
		$this->db->where('room_type_id', $room_type_id);
		$this->db->where('deleted', 'no');
		$this->db->order_by('room_number', 'asc');
		
		return $this->db->get();
	}
	
	function select_resv_room($date, $room_id) {
		$this->db->select('*');
		$this->db->from('reservation_room as rr');
		$this->db->join('room as r', 'r.room_id=rr.room_id', 'left');
		$this->db->join('reservation as resv', 'resv.resv_id=rr.resv_id', 'left');
		$this->db->join('guest as g', 'g.guest_id=resv.guest_id', 'left');
		$this->db->where('rr.resv_room_date', $date);
		$this->db->where('rr.room_id', $room_id);
		$this->db->where('rr.deleted', 'no');
		$this->db->order_by('rr.check_in_time', 'desc');
		$this->db->limit(1);
		
		return $this->db->get();
	}
}